import { AsyncStorage } from 'react-native';
import jwtDecode from 'jwt-decode';

// don't handle the error
const setToken = async (token) => { await AsyncStorage.setItem('token', token); };

// don't handel the error
const getToken = async () => AsyncStorage.getItem('token');

// for test, shouldn't be called usually
const removeToken = async () => AsyncStorage.removeItem('token');

const getInfo = async () => {
  const token = await getToken();
  return token && jwtDecode(token);
};

export {
  setToken, getToken, removeToken, getInfo
};
